package day14;

public class homework00002 extends Thread {
    homework002 h02;

    public homework00002(homework002 h02) {
        this.h02 = h02;
    }

    @Override
    public void run() {
        synchronized (h02.getlock()) {
            while (h02.getCount() > 0) {
                if (h02.isFlag()) {
                    try {
                        h02.getlock().wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                } else {
                    for (int i = 0; i < 5; i++) {
                        System.out.println("这是主程序");
                        try {
                            Thread.currentThread().sleep(100);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                    h02.setFlag(true);
                    h02.setCount(h02.getCount() - 1);
                    h02.getlock().notify();
                }
            }
        }
    }
}
